/*-*
 * FILENAME  :
 *    $HeadURL$
 *
 * STATUS  :
 *    $Revision$
 *
 *    $Author$
 *    $Date$
 *  
 *    
 * Copyright (c) 2011 Gonalge Ltda. All rights reserved.
 *
 ****************************************************************/

package org.gonalge.sudoku.presentacion;

import javax.swing.DebugGraphics;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import java.awt.Color;
import java.awt.Font;
import java.awt.Panel;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.gonalge.sudoku.util.FormUtils;

/**
 * 
 * @author Geremias Gonzalez
 */
public class PanelAyuda extends Panel {

    /**
     * 
     */
    private static final long serialVersionUID = -6719326280133805976L;

    private final FormUtils formUtils = new FormUtils();

    private final JButton salir = new JButton();

    private final ImageIcon a1 = new ImageIcon(formUtils.getImagen("ayu1"));

    private final ImageIcon a2 = new ImageIcon(formUtils.getImagen("ayu2"));

    private final ImageIcon a3 = new ImageIcon(formUtils.getImagen("ayu3"));

    private final JLabel fondo = new JLabel();

    private final JLabel texto = new JLabel();

    private final JButton sig = new JButton();

    private final JButton atr = new JButton();

    private int pag = 1;

    public PanelAyuda() {

        try {
            init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void init() throws Exception {

        this.setLayout(null);
        this.setBounds(new Rectangle(0, 0, 1024, 805));
        salir.setBounds(new Rectangle(845, 445, 154, 82));
        salir.setFont(new Font("Dialog", 1, 17));
        salir.setBorderPainted(false);
        salir.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
        salir.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jButton1_actionPerformed(e);
            }
        });

        texto.setBounds(new Rectangle(170, 45, 554, 601));
        texto.setIcon(a1);
        texto.setBackground(new Color(33, 33, 255));

        sig.setBounds(new Rectangle(850, 130, 140, 36));
        sig.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jButton2_actionPerformed(e);
            }
        });

        atr.setBounds(new Rectangle(850, 175, 140, 36));
        atr.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                atr_actionPerformed(e);
            }
        });

        sig.setIcon(new ImageIcon(formUtils.getImagen("sig2")));
        sig.setRolloverIcon(new ImageIcon(formUtils.getImagen("sig1")));

        sig.setIcon(new ImageIcon(formUtils.getImagen("sig2")));
        sig.setRolloverIcon(new ImageIcon(formUtils.getImagen("sig1")));

        sig.setBorderPainted(false);
        sig.setBackground(Color.black);
        sig.setOpaque(false);
        atr.setIcon(new ImageIcon(formUtils.getImagen("atr2")));
        atr.setRolloverIcon(new ImageIcon(formUtils.getImagen("atr1")));

        salir.setIcon(new ImageIcon(formUtils.getImagen("sal1")));
        salir.setRolloverIcon(new ImageIcon(formUtils.getImagen("sal2")));

        salir.setOpaque(false);
        atr.setBorderPainted(false);
        atr.setBackground(Color.black);
        atr.setOpaque(false);

        fondo.setIcon(new ImageIcon(formUtils.getImagen("fondo")));
        fondo.setBounds(new Rectangle(0, 0, fondo.getIcon().getIconWidth(), fondo.getIcon().getIconHeight()));

        this.add(atr, null);
        this.add(sig, null);
        this.add(texto, null);
        this.add(salir, null);
        this.add(fondo, null);
        this.setVisible(false);

    }

    private void jButton1_actionPerformed(ActionEvent e) {
        this.setVisible(false);
    }

    public void empesar() {
        pag = 1;
        texto.setIcon(new ImageIcon(formUtils.getImagen("ayu1")));
    }

    private void jButton2_actionPerformed(ActionEvent e) {

        if (pag < 3) {
            pag++;
            switch (pag) {
                case 1:
                    texto.setIcon(a1);
                    break;
                case 2:
                    texto.setIcon(a2);
                    break;
                case 3:
                    texto.setIcon(a3);
            }
        }
    }

    private void atr_actionPerformed(ActionEvent e) {
        if (pag > 1) {
            pag--;
            switch (pag) {
                case 1:
                    texto.setIcon(a1);
                    break;
                case 2:
                    texto.setIcon(a2);
                    break;
                case 3:
                    texto.setIcon(a3);
            }
        }
    }
}
